package org.luckystrophe.snowtoms.manager;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import android.content.Context;
import android.location.Address;
import android.location.Geocoder;

import com.googlecode.androidannotations.annotations.EBean;
import com.googlecode.androidannotations.api.Scope;

@EBean(scope = Scope.Singleton)
public class GeocodeManager {

	private Geocoder geoCoder;

	public void initContext(Context context) {
		geoCoder = new Geocoder(context, Locale.KOREA);
	}

	public String convertCoordinateToAddress(double lat, double lng) {
		List<Address> addresses;
		StringBuffer address = new StringBuffer();
		try {
			addresses = geoCoder.getFromLocation(lat, lng, 1);
			for (Address addr : addresses) {
				int index = addr.getMaxAddressLineIndex();
				for (int i = 0; i <= index; i++) {
					address.append(addr.getAddressLine(i));
					address.append(" ");
				}
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return address.toString();
	}

}
